package org.brakepedal.server.support.http;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

/**
 * Date: 2023/2/11 20:59
*/
@JsonDeserialize
public class ResponseBodyMsg implements EnumConverter<String,String>{

    public final static ResponseBodyMsg TOO_LARGER_PAGE = new ResponseBodyMsg("did you deliver pageNum or pageSize? total records are too large to deliver by network!");

    public final static ResponseBodyMsg DEFAULT_WARN = new ResponseBodyMsg("This operation is failed!");

    public final static ResponseBodyMsg DEFAULT_ERROR =new ResponseBodyMsg("Something broken!");

    public final static ResponseBodyMsg DEFAULT_SUCCESS = new ResponseBodyMsg("OK");

    public final static ResponseBodyMsg UPDATE_SUCCESS = new ResponseBodyMsg("UPDATE_SUCCESS");

    public final static ResponseBodyMsg UPDATE_ERROR = new ResponseBodyMsg("UPDATE_ERROR");

    public final static ResponseBodyMsg OK = DEFAULT_SUCCESS;

    public final static ResponseBodyMsg SAVE_SUCCESS = new ResponseBodyMsg("SAVE_SUCCESS");

    public final static ResponseBodyMsg SAVE_ERROR = new ResponseBodyMsg("SAVE_ERROR");

    public final static ResponseBodyMsg DELETE_SUCCESS = new ResponseBodyMsg("DELETE_SUCCESS");
    public final static ResponseBodyMsg DELETE_ERROR = new ResponseBodyMsg("DELETE_ERROR");

    private final String value;

    @Contract(pure = true)
    public static @NotNull ResponseBodyMsg warn(@NotNull String msg) {
        return new ResponseBodyMsg("Operation: '"+msg+"' is failed!");
    }

    @Contract(pure = true)
    public static @NotNull ResponseBodyMsg error(@NotNull String msg) {
        return new ResponseBodyMsg("Operation: '" + msg + "' cause error!");
    }

    @Contract(pure = true)
    public static @NotNull ResponseBodyMsg success(@NotNull String msg) {
        return new ResponseBodyMsg("Operation: '"+msg+"' success!");
    }

    @Contract(pure = true)
    public static @NotNull ResponseBodyMsg custom(@NotNull String msg) {
        return new ResponseBodyMsg(msg);
    }

    private ResponseBodyMsg(String value) {
        this.value = value;
    }

    @JsonValue
    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "msg{"+ value +'}';
    }
}
